package com.itheima.web.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/html/**").addResourceLocations("classpath:/html/");
        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/js/**").addResourceLocations("classpath:/html/js/");
        registry.addResourceHandler("/css/**").addResourceLocations("classpath:/html/css/");
        registry.addResourceHandler("/img/**").addResourceLocations("classpath:/html/img/");
        registry.addResourceHandler("/fonts/**").addResourceLocations("classpath:/html/fonts/");
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**") // 拦截所有
                .excludePathPatterns("/system/users/verification", "/system/users/login","/backend/**","/error","/","/favicon.ico","/html/**","/css/**","/js/**","/management/**","/management/system/users/login*","/management/system/users/profile*","/img/**","/fonts/**");// 排除登录和验证码
    }
}
